var prefix = jsctx + "/inviteLink";

var inviteLink = (function () {
    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
        load();
    };

    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    function load() {
        $('#exampleTable')
            .bootstrapTable({
                method: 'get',
                url: prefix + "/listInviteLink",
                iconSize: 'outline',
                toolbar: '#exampleToolbar',
                striped: false,
                dataType: "json",
                pagination: true,
                singleSelect: false,
                pageSize: 20,
                pageList: [20],
                pageNumber: 1,
                sidePagination: "server",
                cache: false,
                queryParams: function (params) {
                    return {
                        limit: params.limit,
                        offset: (params.offset / params.limit) + 1,
                        inviteSettingId: $("#inviteSettingId").val().trim(),
                        nickname: $("#nickname").val().trim(),
                        mobile: $("#mobile").val().trim()
                    };
                },
                columns: [
                    {
                        field: 'number',
                        title: '序号',
                        width: '100', align: 'center',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {field: 'nickname', title: '邀请者', align: 'left', width: '100'},
                    {field: 'mobile', title: '邀请者手机号', align: 'left', width: '100'},
                    {field: 'inviteLinkCount', title: '邀请人数', align: 'left', width: '100'},
                    {field: 'inviteTicketTypeCount', title: '获得优惠券', align: 'left', width: '100'},
                    {
                        title: '操作',
                        field: '邀请明细',
                        width: '200', align: 'center',
                        formatter: function (value, row, index) {
                            // var a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="邀请明细" onclick="inviteLink.inviteLinkDetail(\''
                            //     + row.memberId
                            //     + '\')">邀请明细</a> ';
                            // var a = '<a class="btn btn-success btn-sm ' + has_edit + '" href=" " title="邀请明细" onclick="inviteLink.inviteLinkDetail(\''
                            //     + row.memberId + '\',\'' + row.inviteSettingId
                            //     + '\')">邀请明细</ a> ';

                            var a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" mce_href="#" title="邀请明细" onclick="inviteLink.inviteLinkDetail(\''
                                + row.memberId + '\',' + '\'' + row.inviteSettingId +
                                '\')">邀请明细</a> ';

                            return a;
                        }
                    }
                ]
            });
    };

    function inviteLinkDetail(memberId, inviteSettingId) {
        location.href = prefix + "/inviteLinkDetail/" + memberId+ "/" + inviteSettingId;
        // location.href = prefix + "/editHlhtDiscount/" + discountStationId + "/" + tenantType;
    }

    return {
        init: init,
        reLoad: reLoad,
        inviteLinkDetail: inviteLinkDetail
    };
})();

